//
//  LWRetweetedView.m
//  1.28  weibo
//
//  Created by mac on 15/2/21.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "LWRetweetedView.h"
#import "LWstatuses.h"
@interface LWRetweetedView ()

@property (weak, nonatomic) IBOutlet UILabel *retweetedLable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *retweetedViewContant;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *retweetedPhotoConstant;
@property (weak, nonatomic) IBOutlet UICollectionView *retweetedPhotoView;

/**
 *  是否是转发到微博
 */
@property (nonatomic,assign) BOOL isRetweeted;

@end
@implementation LWRetweetedView

- (void)awakeFromNib {
    //设置原创微博的最大宽度
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    //设置转发微博的宽度
    self.retweetedLable.preferredMaxLayoutWidth = width - 10;
    //self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setStatus:(LWstatuses *)status{

    [super setStatus:status];
    
    LWstatuses *retweeted = self.status.retweeted_status;
    //2 转发微博
    if (retweeted != nil) {
        
        self.hidden = NO;
        [self retweetedStatus];
    }else{

        self.hidden = YES;
        self.retweetedViewContant.constant = 0;
    }
}
- (void)retweetedStatus{

    LWstatuses *retweeted = self.status.retweeted_status;
    //设置转发文本
    self.retweetedLable.text = [NSString stringWithFormat:@"@%@:\n%@",retweeted.user.name,retweeted.text];
    //设置文本的高度
    self.retweetedViewContant.constant = [self.retweetedLable systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 10;
    //转发带配图的微博
    //判断是否有配图
    NSInteger count = retweeted.pic_urls.count;
    if (count > 0) {
        NSInteger row = 0;
        //1.计算有几行
        if (count % 3 == 0) {
            row = count / 3;
        }else{
            row = count / 3 + 1;
        }
        //3.设置配图的高度
        CGFloat photoHeight = 70;
        CGFloat photoMargin = 10;
        CGFloat photoCollectionHeight = row * photoHeight + (row - 1) * photoMargin;
        self.retweetedPhotoConstant.constant = photoCollectionHeight;
        [self.retweetedPhotoView reloadData];
        //4.修改原创微博的高度
        self.retweetedViewContant.constant += self.retweetedPhotoConstant.constant + 10;
        
    }else{
        
        self.retweetedPhotoConstant.constant = 0;
    }
    
}



@end
